Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert custom_associations to array of symbols #356

Merged
merged 1 commit into from
May 19, 2023

Conversation

shioyama
Copy link
Member

@shioyama shioyama commented May 18, 2023

What are you trying to accomplish?

Having symbols in a yaml array is less natural than an array of strings, yet if you set an array of strings for custom_associations then Packwerk will simply ignore them without any error.

And actually, the example config itself has an array of strings:

# List of custom associations, if any
# custom_associations:
# - "cache_belongs_to"

What approach did you choose and why?

Just convert them to symbols when assigning from yaml.

What should reviewers focus on?

Why wasn't Sorbet blowing up on this? There's a T.let assigning to an array of symbols, yet it was assigning an array of Strings, that should be a problem. 🤔

Type of Change

  • Bugfix
  • New feature
  • Non-breaking change (a change that doesn't alter functionality - i.e., code refactor, configs, etc.)

Additional Release Notes

  • Breaking change (fix or feature that would cause existing functionality to change)

Include any notes here to include in the release description. For example, if you selected "breaking change" above, leave notes on how users can transition to this version.

If no additional notes are necessary, delete this section or leave it unchanged.

Checklist

  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • It is safe to rollback this change.

@shioyama shioyama force-pushed the shioyama/convert_custom_associations_to_symbols branch from 5935590 to 8ef194d Compare May 18, 2023 00:44
@shioyama shioyama force-pushed the shioyama/convert_custom_associations_to_symbols branch from 8ef194d to 066bd48 Compare May 18, 2023 00:45
@@ -75,7 +75,7 @@ def initialize(configs = {}, config_path: nil)
root = config_path ? File.dirname(config_path) : "."
@root_path = T.let(File.expand_path(root), String)
@package_paths = T.let(configs["package_paths"] || "**/", T.any(String, T::Array[String]))
@custom_associations = T.let(configs["custom_associations"] || [], T::Array[Symbol])
@custom_associations = T.let((configs["custom_associations"] || []).map(&:to_sym), T::Array[Symbol])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused why Sorbet wasn't blowing up on this since the array wasn't an array of symbols 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah configs is a hash with untyped values.

@shioyama shioyama marked this pull request as ready for review May 18, 2023 00:47
@shioyama shioyama requested a review from a team as a code owner May 18, 2023 00:48
@shioyama shioyama requested a review from rafaelfranca May 18, 2023 01:16
Copy link
Contributor

@davidstosik davidstosik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I too am surprised this has not been a problem already.

Looks like the packwerk.yml template would have given wrong instructions?

# List of custom associations, if any
# custom_associations:
# - "cache_belongs_to"

Fix looks good to me! 👍🏻

@@ -42,7 +42,7 @@ class ConfigurationTest < Minitest::Test
assert_equal ["{exclude_dir,bin,tmp}/**/*"], configuration.exclude
assert_equal app_dir, configuration.root_path
assert_equal "**/*/", configuration.package_paths
assert_equal ["custom_association"], configuration.custom_associations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yet if you set an array of strings for custom_associations then Packwerk will simply ignore them without any error.

So this test was "right", but testing an invalid scenario?

@shioyama shioyama merged commit 0fa19dc into main May 19, 2023
@shioyama shioyama deleted the shioyama/convert_custom_associations_to_symbols branch May 19, 2023 07:52
@shopify-shipit shopify-shipit bot temporarily deployed to rubygems August 8, 2023 20:48 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants